package ynu.edu.Entity;

import com.google.gson.Gson;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;//业务状态码  0-成功  1-失败
    private String message;//提示信息
    private T data;//响应数据

    static Gson gson = new Gson();

    //快速返回操作成功响应结果(带响应数据)
    public static <E> String success(E data) {
        return gson.toJson(new Result<>(0, "操作成功", data));
    }

    //快速返回操作成功响应结果
    public static String success() {
        return gson.toJson(new Result<>(0, "操作成功", null));
    }

    public static String error(String message) {
        return gson.toJson(new Result<>(1, message, null));
    }
}
